Public Class FormManagement

#Region "Declarations"
  Private m_ParentForm As frmMain
  Private m_FormList(FormName.NUMNAME) As Form
  Private m_CurrentFormName As FormName

  Public Enum FormName
    NONE = -1
    LOGIN = 0
		ORDERLIST
		PRODUCTLIST
		MATERIALLIST
		EMPLOYEELIST
    CONNECTSERVER
    USERMANAGEMENT
    NUMNAME
  End Enum
#End Region

#Region "Properties"

  Public Property ParentForm() As Form
    Get
      ParentForm = m_ParentForm
    End Get
    Set(ByVal value As Form)
      m_ParentForm = value
    End Set
  End Property

  Public Property CurrentFormName() As FormName
    Get
      Return m_CurrentFormName
    End Get
    Set(ByVal value As FormName)
      m_CurrentFormName = value
    End Set
  End Property

  Public ReadOnly Property CurrentForm() As Form
    Get
      Return m_FormList(CurrentFormName)
    End Get
  End Property

#End Region

#Region "New"

  Public Sub New(ByVal ParentForm As Form)
    m_ParentForm = ParentForm
    m_CurrentFormName = FormName.NONE
  End Sub

#End Region

#Region "Methods"
  Public Sub CloseAll()
    Dim item As Object
    For i = 0 To FormName.NUMNAME
      item = m_FormList(i)
      If Not IsNothing(item) Then
        Try
          item.Close()
          item = Nothing
          m_FormList(i) = Nothing
        Catch ex As Exception
          'MessageBox.Show(ex.Message, Resource.GetString(ResourceType.Caption, "Error"))
        End Try
      End If
    Next

    m_CurrentFormName = FormName.NONE
  End Sub
  Public Sub ShowForm(ByVal frmName As FormName)
    If frmName = m_CurrentFormName Then
      Return
    End If
    Dim item As Form
    For Each item In m_FormList
      If Not IsNothing(item) Then
        Try
          item.Close()
          item.Dispose()
        Catch ex As Exception
          'MessageBox.Show(ex.Message, Resource.GetString(ResourceType.Caption, "Error"))
        End Try
      End If
    Next

    Select Case frmName
      '      Case FormName.ConnectServer
      '        m_ParentForm.Hide()
      '        Me.CurrentFormName = FormName.ConnectServer
      '        Dim f_Connect As New frmConnect
      '        f_Connect.ShowDialog(m_ParentForm)
      '        m_FormList(frmName) = f_Connect
      '        If f_Connect.DialogResult = DialogResult.Cancel Then
      '          End
      '        End If
      '        If GetPrivilegeFunction(FunctionName.MACHINE_MANAGEMENT) <> PrivilegeFunction.NONE And m_gObjLicense.CheckLicense() = True Then
      '          m_ParentForm.rbtnMachine.SelfClick()
      '        End If
      '          
      '
      '      Case FormName.Login
      '        m_ParentForm.Hide()
      '        Me.CurrentFormName = FormName.Login
      '        Dim f_login As New frmLogin
      '        f_login.ShowDialog(m_ParentForm)
      '        m_FormList(frmName) = f_login
      '        If f_login.DialogResult = DialogResult.Cancel Then
      '          End
      '        End If
      '        If GetPrivilegeFunction(FunctionName.MACHINE_MANAGEMENT) <> PrivilegeFunction.NONE And m_gObjLicense.CheckLicense() = True Then
      '          m_ParentForm.rbtnMachine.SelfClick()
      '        End If

      Case FormName.ORDERLIST
        Me.CurrentFormName = FormName.ORDERLIST
        Dim f_MachineList As New frmOrderManage
        f_MachineList.MdiParent = m_ParentForm
        f_MachineList.Dock = DockStyle.Fill
        f_MachineList.Show()
        m_FormList(frmName) = f_MachineList

      Case FormName.MATERIALLIST
        Me.CurrentFormName = FormName.MATERIALLIST
        Dim f_MaterialList As New frmMaterialManage
        f_MaterialList.MdiParent = m_ParentForm
        f_MaterialList.Dock = DockStyle.Fill
        f_MaterialList.Show()
				m_FormList(frmName) = f_MaterialList

			Case FormName.PRODUCTLIST
				Me.CurrentFormName = FormName.PRODUCTLIST
				Dim f_ProductList As New frmProductManage
				f_ProductList.MdiParent = m_ParentForm
				f_ProductList.Dock = DockStyle.Fill
				f_ProductList.Show()
				m_FormList(frmName) = f_ProductList
		End Select

    'frmMain.UpdateButtonStates()
  End Sub

  Public Sub ShowNewSession()
    Dim f As Form = Nothing
    Dim fArr As New ArrayList()
    Dim i As Integer = 0
    For i = Application.OpenForms.Count - 1 To 0 Step -1
      f = Application.OpenForms.Item(i)
      If f.Modal Then
        fArr.Add(f)
      End If
    Next
    For i = 0 To fArr.Count - 1
      f = fArr(i)
      Try
        f.Close()
        f.Dispose()
      Catch ex As Exception
        'MessageBox.Show(ex.Message, Resource.GetString(ResourceType.Caption, "Error"))
      End Try
    Next
    m_ParentForm.Show()
    Me.CurrentFormName = FormName.NONE
    m_ParentForm.Text = "Machine managerment"
  End Sub

#End Region

End Class
